#include<bits/stdc++.h>
using namespace std;
int T,n,a[50],num,lb,lr,ans;
void dfs(int step)
{
    if(step>n)
    {
        ans=max(ans,num);
        return;
    }
    int q=lb;
    if(a[step]==a[lb])num+=a[lb];
    lb=step;
    dfs(step+1);
    lb=q;
    if(a[step]==a[lb])num-=a[lb];
    int p=lr;
    if(a[step]==a[lr])num+=a[lr];
    lr=step;
    dfs(step+1);
    lr=p;
    if(a[step]==a[lr])num-=a[lr];
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--)
    {
        ans=0;
        lb=lr=0;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        dfs(1);
        cout<<ans<<endl;
    }

    return 0;
}
